import allure
from selenium import webdriver
from selenium.webdriver.common.by import By

from base.base_page import BasePage


class PageLogin(BasePage):
    # def __init__(self,driver):   不要了，因为继承了BasePage，BasePage有driver属性了
    #     self.__driver=driver
    # 输入用户名
    @allure.step("1、输入用户名")
    def __input_username(self,username):
        self.input_page_element((By.CSS_SELECTOR,"#username"),username)
        # self.__driver.find_element(By.CSS_SELECTOR,"#username").send_keys(username)
    #输入密码
    @allure.step("2、输入密码")
    def __input_password(self,password):
        self.input_page_element((By.CSS_SELECTOR,"#password"),password)
        # self.__driver.find_element(By.CSS_SELECTOR,"#password").send_keys(password)
    #输入验证码
    @allure.step("3、输入验证码")
    def __input_verify_code(self,verify_code):
        self.input_page_element((By.CSS_SELECTOR,"#verify_code"),verify_code)
        # self.__driver.find_element(By.CSS_SELECTOR,"#verify_code").send_keys(verify_code)
    #点击登录按钮
    @allure.step("4、点击登录按钮")
    def __click_login_button(self):
        self.click_page_element((By.CSS_SELECTOR,"a[name='sbtbutton']"))
        # self.__driver.find_element(By.CSS_SELECTOR,"a[name='sbtbutton']").click()

    #获取登录成功的文本值
    # 返回登录成功的文本值
    def get_login_success_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,".mu-m-phone"))

    #登录失败的文本值
    def get_login_fail_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,".layui-layer-content.layui-layer-padding"))

    def login(self,username,password,verify_code):
        self.__input_username(username)
        self.__input_password(password)
        self.__input_verify_code(verify_code)
        self.__click_login_button()

